
package com.zoweunion.mechanic.sqlprovider;

import java.util.Map;

import org.apache.ibatis.jdbc.SQL;

/**
 * @Description:  
 * @author: 王春伟 
 * @date:   2018年12月28日 下午7:07:50    
 * @Copyright: 2018 www.zoweunion.com Inc. All rights reserved.
 */
public class TuiHuanSqlProvider {

	//硬件申请退换
	public String applyTuiHuan() {

		return "INSERT INTO T_O_SS_RETURN(id,s_id,return_type,apply_time,quantity,handle_status,delete_flag,update_user,update_time,create_user,create_time,remark)"
				+ " VALUES(#{id},#{s_id},#{return_type},now(),#{quantity},0,0,#{user},now(),#{user},now(),'记录硬件申请退换记录')";

	}
	//根据服务商的id查询服务商的名称
	public String getSnameBySid() {

		return "SELECT tss.user_name,tsd.status FROM T_S_SS_SERVER tss LEFT JOIN t_o_ss_server_depot tsd ON tsd.s_id=tss.id WHERE tss.id = #{s_id}";

	}

	//将服务商申请记录插入相关的表中
	public String applyPurchase() {

		return "INSERT INTO t_o_ss_purchase(id,s_id,s_name,num,count,model,brand,mobile_phone,apply_time,delete_flag,update_user,update_time,remark,create_user,create_time,status)"
				+ " VALUES(#{id},#{s_id},#{s_name},#{num},#{count},#{model},#{brand},#{mobile_phone},now(),0,#{user},now(),'记录服务商申请采购记录',#{user},now(),0)";

	}

	//根据条件模糊查询设备采购列表
	public String getPurchaseByCondition(Map<String, Object> reqMap) {

		return new SQL() {
			{
				SELECT ("*");
				FROM("t_o_ss_purchase");				
				if (reqMap.get("s_name") != null && !"".equals(reqMap.get("s_name").toString())) {
					WHERE("s_name LIKE #{s_name}");
				}
				if (reqMap.get("model") != null && !"".equals(reqMap.get("model").toString())) {
					WHERE("model LIKE #{model}");
				}
				if (reqMap.get("brand") != null && !"".equals(reqMap.get("brand").toString())) {
					WHERE("brand LIKE #{brand}");
				}
				if (reqMap.get("mobile_phone") != null && !"".equals(reqMap.get("mobile_phone").toString())) {
					WHERE("mobile_phone LIKE #{mobile_phone}");
				}
				if (reqMap.get("apply_time") != null && !"".equals(reqMap.get("apply_time").toString())) {
					WHERE("apply_time LIKE #{apply_time}");
				}
			
		}	
		}.toString();

	}
}
